package homework2;

public class InitMatch implements ITournament {

	public MatchData data;

	public InitMatch(MatchData data) {
		this.data = data;
	}

	public boolean allValid() {
		return data.score.isValid();
	}

	public int matchesPlayed(IBaseSport name) {
		if (data.team1.equals(name) || data.team2.equals(name)) {
			return 1;
		}

		return 0;
	}

	@Override
	public boolean hasInvariant() {
		return true;
	}

	@Override
	public int depth() {
		return 1;
	}

	@Override
	public int lowestRank() {
		return Math.min(((IRanked) data.team1).getRank(),
				((IRanked) data.team2).getRank());
	}

	@Override
	public int highestRank() {
		return Math.max(((IRanked) data.team1).getRank(),
				((IRanked) data.team2).getRank());
	}

	@Override
	public boolean balancedRanking(int middleRank) {
		return ((IRanked) data.team1).getRank() <= middleRank
				&& ((IRanked) data.team2).getRank() >= middleRank;
	}

	@Override
	public boolean winnerAlwaysAdvanced() {
		return true;
	}

	public IBaseSport winnerMovesOn() {
		return this.data.matchWinner();
	}

}
